/*
 * F_Consola.c
 *
 *  Created on: 04/11/2011
 *      Author: tacho
 */

#include "../../headers/GlobalHeaderPFS.h"
#include "../../headers/Constantes_PFS.h"

extern int32_t sali;

/*-------------------------------------------------------------------------*/
/**
 */
void consolaPFS(){
	char buffer[MAX_LINE];

		while(sali==0){
				printf("COMMAND-> ");
				fgets(buffer,MAX_LINE,stdin);
				consolaPFS_AnalizoComando(buffer);
				printf("\n");

			}
		return ;
}

/*-------------------------------------------------------------------------*/
/**
 Recibe un comando a ejectuar.
 */

void consolaPFS_AnalizoComando(char *buffer){

		int32_t entro = 0;
		if(!validoMedianteRegex(buffer,"fsinfo+[\n]")){

			comandofsinfo();
			entro =1;
		}
		if(!validoMedianteRegex(buffer,"finfo[[:blank:]][[:alnum:][:digit:][:punct:]]+[\n]")){
			comandofinfo(buffer);
			entro = 1;
		}

		if(!entro)	printf("Ingrese nuevamente el comando");

		if(strcmp(buffer,"exit")==0){
			sali = 1;
		}
	}
/*-------------------------------------------------------------------------*/
/**

 */
uint32_t validoMedianteRegex(char* textoParaValidar, char * pattern){
	regex_t    preg;
	int        rc;
	size_t     nmatch = 2;
	regmatch_t pmatch[2];

	if (0 != (rc = regcomp(&preg, pattern, REG_EXTENDED))) {
		printf("regcomp() failed, returning nonzero (%d)\n", rc);
        exit(EXIT_FAILURE);
    }

	rc = regexec(&preg, textoParaValidar, nmatch, pmatch, 0);
    regfree(&preg);
    return rc;
}
